<?php
namespace app\http\controller\v1_0_0;

use kernel\library\Controller;
use kernel\library\Env;
use kernel\library\Request;
use kernel\library\XCache;

class Log extends Controller
{
    public function write(Request $request){
        //写到队列里面去
        $key = Env::get('LOG_TOPIC');
        $xcache = XCache::getInstance();
        $inputData = json_decode($request->all(false)['data'], true);
        $queueData = [
            'time' => $inputData['time'],
            'url' => $inputData['url'],
            'method' => $inputData['method'],
            'serve' => $inputData['serve'],
            'remoteip' => $inputData['remoteip'],
            'rescode' => $inputData['rescode'],//拿到状态码
            'msg' => json_encode($inputData['msg'], JSON_UNESCAPED_SLASHES + JSON_UNESCAPED_UNICODE),
            'log' =>  json_encode($inputData['log'], JSON_UNESCAPED_SLASHES + JSON_UNESCAPED_UNICODE),
            'use_memory' => $inputData['use_memory'],
            'peak_memory' => $inputData['peak_memory'],
            'runtime' => $inputData['runtime'],
        ];
        $res = $xcache->handler()->rPush($key, json_encode($queueData, JSON_UNESCAPED_SLASHES + JSON_UNESCAPED_UNICODE));
        return $this->result([$key => $queueData]);
    }
}

